package com.aiyige.model.request;

import com.aiyige.base.api.ApiManager;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;

/**
 * Created by zhuyakun on 2017/10/31.
 */

public class UploadAvatarRequest {

    public static Builder newBuilder() {
        return new Builder();
    }

    public static final class Builder {
        private String imagePath;

        private Builder() {
            imagePath = "";
        }

        public Builder imagePath(String imagePath) {
            this.imagePath = imagePath;
            return this;
        }

        public Call<ResponseBody> build() {
            File imageFile=new File(imagePath);
            RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), imageFile);
            return ApiManager.getService().uploadAvatar(MultipartBody.Part.createFormData("file", imageFile.getName(), requestBody));
        }
    }
}
